package com.xoa.util.channel;


import com.xoa.dao.smsSettings.SmsSettingsMapper;
import com.xoa.dao.users.UserExtMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.smsSettings.SmsSettings;
import com.xoa.util.channel.bean.Mo;
import com.xoa.util.channel.bean.StatusReport;
import com.xoa.util.channel.httpclient.SDKHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.net.URLEncoder;
import java.util.List;

/**
 *
 * @项目名称：EmayClientForHttpV1.0?
 * @类描述：??
 * @创建人：HL.W??
 * @创建时间：2015-9-9 下午5:29:46??
 * @修改人：HL.W??
 * @修改时间：2015-9-9 下午5:29:46??
 * @修改备注：
 */
@Controller
public class SDKClientTest {

    @Autowired
    private UsersMapper usersMapper;

    @Autowired
    private UserExtMapper userExtMapper;

    @Resource
    SmsSettingsMapper smsSettingsMapper;
    public  String SendMsg(List<String> mobleList,String model1,String contextString) throws Exception {
        String mdn = "";
        if (mobleList.size()==1){
            mdn = mobleList.get(0);
        }else {
            mdn=model1;
        }
        SmsSettings smsSettings = smsSettingsMapper.selectUse();
        String message = smsSettings.getSign()+contextString+"。 请登录cs生态综合办公PC端或cs生态APP及时处理。";
        message = URLEncoder.encode(message, "UTF-8");
        String code = "888";
        long seqId = System.currentTimeMillis();
        String param = "cdkey=" + smsSettings.getUsername().split("=")[1] + "&password=" + smsSettings.getPwd().split("=")[1] + "&phone=" + mdn + "&message=" + message + "&addserial=" + code + "&seqid=" + seqId;
        String url = smsSettings.getProtocol()+"://"+smsSettings.getHost()+"/"+smsSettings.getPort()+"/" + "sendtimesms.action";
        String ret = SDKHttpClient.sendSMS(url, param);
        System.out.println("发送结果:" + ret);
        return ret;
    }
}
